<?php

namespace Fluency\Routing;

use Fluency\Request;

/**
 * @package Fluency\Routing
 * @author  Ignas Rudaitis
 * @version 2.0.0
 */
class PresetRouter implements Router
{
    private $routes;
    private $reverseRoutes;

    public function __construct(array $routes)
    {
        $this->routes = $routes;
        $this->reverseRoutes = array_flip($routes);
    }

    public function createRequest($url)
    {
        $url = trim($url, "/");
        $route = &$this->routes[$url];
        if (isset($route)) {
            if (is_string($route)) {
                $route = Request::forAction($route);
            }
            return $route;
        }
    }

    public function createUrl($action, array $params = array())
    {
        if (empty($params) && isset($this->reverseRoutes[$action])) {
            return $this->reverseRoutes[$action];
        }
    }
}